cmake_minimum_required(VERSION 3.30)
project(hello_grpc)

set(CMAKE_CXX_STANDARD 20)

# ref: https://cmake.org/cmake/help/latest/module/FindProtobuf.html
find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
message(STATUS "Using protobuf ${Protobuf_VERSION}")
# -- Using gRPC 1.71.0
# -- Using protobuf 5.29.3

add_library(helloworld_proto proto/helloworld.proto)
target_link_libraries(helloworld_proto PUBLIC gRPC::grpc++)
target_include_directories(helloworld_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate(TARGET helloworld_proto)
protobuf_generate(
        TARGET helloworld_proto
        LANGUAGE grpc
        PLUGIN protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
        PLUGIN_OPTIONS generate_mock_code=true
        GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc)

add_executable(server server/main.cpp)
target_link_libraries(server PRIVATE helloworld_proto gRPC::grpc++ gRPC::grpc++_reflection protobuf::libprotobuf)

add_executable(client client/main.cpp)
target_link_libraries(client PRIVATE helloworld_proto gRPC::grpc++ gRPC::grpc++_reflection protobuf::libprotobuf)